const {Controller} = require('egg');
const tencentcloud = require("tencentcloud-sdk-nodejs-nlp");
const tencentcloud2 = require("tencentcloud-sdk-nodejs-fmu");
const fs = require("fs");
class HomeController extends Controller {
	async index() {
		const {ctx} = this;//const ctx=this.ctx
		ctx.body = '你好,成都理工';
	}
	
	async aifacegood(){
		// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
		
		
		const FmuClient = tencentcloud2.fmu.v20191213.Client;
		
		// 实例化一个认证对象，入参需要传入腾讯云账户 SecretId 和 SecretKey，此处还需注意密钥对的保密
		// 代码泄露可能会导致 SecretId 和 SecretKey 泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考，建议采用更安全的方式来使用密钥，请参见：https://cloud.tencent.com/document/product/1278/85305
		// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
		const clientConfig = {
		  credential: {
		    secretId: "AKID6oT1dD1hAXgbJn3BMNYnwxCMMF3hFvSm",
		    secretKey: "IOHvLdpocHpqjQxQhqncDajtz51jS3Vn",
		  },
		  region: "ap-guangzhou",
		  profile: {
		    httpProfile: {
		      endpoint: "fmu.tencentcloudapi.com",
		    },
		  }
		};
		
		
		
		//前端传送的文件
		let files=this.ctx.request.files
		console.log(files)
		
		let data=fs.readFileSync(files[0].filepath)
		let base64img="data:image/png;base64,"+data.toString("base64")
		// console.log(base64img)
		
		// 实例化要请求产品的client对象,clientProfile是可选的
		const client = new FmuClient(clientConfig);
		const params = {
		    "Image": base64img,
		    "Whitening": 100,
		    "Smoothing": 100,
		    "FaceLifting": 100,
		    "EyeEnlarging": 100,
		    "RspImgType": "url"
		};
		let data2=await client.BeautifyPic(params)
		console.log(data2)
		this.ctx.body=data2.ResultUrl
	}
	
	
	async aichat() {
		const {
			ctx
		} = this;
		let query=this.ctx.request.query
		console.log(query)
		
		
		
		
		const NlpClient = tencentcloud.nlp.v20190408.Client;
		
		// 实例化一个认证对象，入参需要传入腾讯云账户 SecretId 和 SecretKey，此处还需注意密钥对的保密
		// 代码泄露可能会导致 SecretId 和 SecretKey 泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考，建议采用更安全的方式来使用密钥，请参见：https://cloud.tencent.com/document/product/1278/85305
		// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
		const clientConfig = {
		  credential: {
		    secretId: "AKID6oT1dD1hAXgbJn3BMNYnwxCMMF3hFvSm",
		    secretKey: "IOHvLdpocHpqjQxQhqncDajtz51jS3Vn",
		  },
		  region: "",
		  profile: {
		    httpProfile: {
		      endpoint: "nlp.tencentcloudapi.com",
		    },
		  },
		};
		
		// 实例化要请求产品的client对象,clientProfile是可选的
		const client = new NlpClient(clientConfig);
		const params = {
		    "Text": query.text,
		    "PoetryType": 2,
		    "Genre": 7
		};
		
		let data=await client.ComposePoetry(params)
		console.log(data)
			
		ctx.body = data//'你好,ai  马上就放学了  开心一点';
	}


}

module.exports = HomeController;
